package com.git.plane;

import java.awt.image.BufferedImage;

/**
 * 英雄机，是飞行物
 * 
 * @author lichao
 *
 * @date 2016年3月14日
 */
public class Hero extends FlyingObject {

	protected BufferedImage[] images = {};// 飞机图形,有2张，发射和不发射
	protected int index = 0;// 此变量交替显示图片的计数
	private int doubleFire;// 火力
	private int life;// 生命值

	public Hero() {
		life = 3;
		doubleFire = 0;
		this.image = ShootGame.hero0;
		images = new BufferedImage[] { ShootGame.hero0, ShootGame.hero1 };
		this.width = image.getWidth();
		this.height = image.getHeight();
		x = 150;
		y = 400;
	}

	/**
	 * Hero类中的移动
	 */
	@Override
	void step() {
		// 设置图片的轮换
		if (images.length > 0) {
			image = images[index++ / 10 % images.length];
		}
	}
	
	public Bullet[] shoot(){
		int xStep = this.width/4;
		int yStep = 20;
		if(doubleFire==0){
			Bullet [] bullets = new Bullet[1];
			bullets[0] = new Bullet(this.x+2*xStep, this.y-yStep);
			doubleFire -=2;
			return bullets;
		}else if(doubleFire==1){
			Bullet [] bullets = new Bullet[2];
			bullets[0] = new Bullet(this.x+xStep, this.y-yStep);
			bullets[1] = new Bullet(this.x+3*xStep, this.y-yStep);
			return bullets;
		}else{
			Bullet [] bullets = new Bullet[3];
			bullets[0] = new Bullet(this.x+xStep, this.y-yStep);
			bullets[1] = new Bullet(this.x+2*xStep, this.y-yStep);
			bullets[2] = new Bullet(this.x+3*xStep, this.y-yStep);
			return bullets;
		}
	}
}
